$(document).ready(function(){
    var IP='39.107.58.193:8080';
    var userId = sessionStorage.getItem('userId');
    console.log(userId);
    $.ajax({ type: "post",
        url:'http://'+IP+'/data-center/CommonReturnBoard/getCommonReturnBoardInfo?token='+userId,
        dataType: "json",
        headers:{"marker":userId},
        data:{"paramData":'{}'},
        success: function (result) {
            console.log(result);
            var data=result.data;
            var str='';
            for(var i=0;i<data.length;i++){
                var imgSrc='../../images/';
                var urlTarget='../';
                var dataModel=data[i].model;
                var dataCondition=data[i].condition.split('"').join("'");
                //console.log(dataCondition);
                if(dataModel=='annual_sales_board') {
                    imgSrc+='ysale.png';//图片路径
                    urlTarget+='yearSale/?dataModel='+dataModel+'&dataCondition='+dataCondition;
                }
                else if(dataModel=='annual_city_board'){
                    imgSrc+='ycity.png';
                    urlTarget+='yearCity/?dataModel='+dataModel+'&dataCondition='+dataCondition;
                }
                else if(dataModel=='annual_route_board'){
                    imgSrc+='ytonglu.png';
                    urlTarget+='yearAccess/?dataModel='+dataModel+'&dataCondition='+dataCondition;
                }
                else if(dataModel=='annual_sku_board'){
                    imgSrc+='ypinlei.png';
                    urlTarget+='yearCategory/?dataModel='+dataModel+'&dataCondition='+dataCondition;
                }
                else if(dataModel=='annual_payments_board'){
                    imgSrc+='ypay.png';
                    urlTarget+='yearPay/?dataModel='+dataModel+'&dataCondition='+dataCondition;
                }
                else if(dataModel=='sale_data'){
                    imgSrc+='msale.png';
                    urlTarget+='monSale/?dataModel='+dataModel+'&dataCondition='+dataCondition;
                }
                else if(dataModel=='sale_vender'){
                    imgSrc+='msmj.png';
                    urlTarget+='monMach/?dataModel='+dataModel+'&dataCondition='+dataCondition;
                }
                else if(dataModel=='sale_twopoints'){
                    imgSrc+='mjtdw.png';
                    urlTarget+='monTraffic/?dataModel='+dataModel+'&dataCondition='+dataCondition;
                }
                else if(dataModel=='sale_mean'){
                    imgSrc+='mdanji.png';
                    urlTarget+='monStand/?dataModel='+dataModel+'&dataCondition='+dataCondition;
                }
                else if(dataModel=='sale_sku'){
                    imgSrc+='mpinlei.png';
                    urlTarget+='monCategory/?dataModel='+dataModel+'&dataCondition='+dataCondition;
                }
                else if(dataModel=='sale_price'){
                    imgSrc+='mjiage.png';
                    urlTarget+='monPrice/?dataModel='+dataModel+'&dataCondition='+dataCondition;
                }
                else if(dataModel=='sale_time'){
                    imgSrc+='yfgcs.png';
                    urlTarget+='monRepurCount/?dataModel='+dataModel+'&dataCondition='+dataCondition;
                }
                else if(dataModel=='sale_redo'){
                    imgSrc+='yfgsku.png';
                    urlTarget+='monRepurSku/?dataModel='+dataModel+'&dataCondition='+dataCondition;
                }
                else if(dataModel=='recent_period_board'){
                    imgSrc+='rtime.png';
                    urlTarget+='recentTime/?dataModel='+dataModel+'&dataCondition='+dataCondition;
                }
                else if(dataModel=='recent_sale_data'){
                    imgSrc+='msale.png';
                    urlTarget+='recentSale/?dataModel='+dataModel+'&dataCondition='+dataCondition;
                }
                else if(dataModel=='recent_sale_vender'){
                    imgSrc+='msmj.png';
                    urlTarget+='recentMach/?dataModel='+dataModel+'&dataCondition='+dataCondition;
                }
                else if(dataModel=='recent_sale_mean'){
                    imgSrc+='mdanji.png';
                    urlTarget+='recentStand/?dataModel='+dataModel+'&dataCondition='+dataCondition;
                }
                else if(dataModel=='recent_sale_sku'){
                    imgSrc+='mpinlei.png';
                    urlTarget+='recentCategory/?dataModel='+dataModel+'&dataCondition='+dataCondition;
                }
                else if(dataModel=='recent_sales_board'){
                    imgSrc+='ysale.png';//图片路径
                    urlTarget+='recentSell/?dataModel='+dataModel+'&dataCondition='+dataCondition;
                }
                str+='<div class="item-wrap">' +
                    '<a href="'+urlTarget+'" target="_self">'+
                    '<div class="item clearfix" id="'+data[i].reportId+'"><div class="img-item">' +
                    '<img src="'+imgSrc+'">' +
                    '</div><div class="txt-item">' +
                    '<p class="name">'+JSON.parse(data[i].condition).boardName+'</p>' +
                    '<p class="txt">'+data[i].time+'</p></div><i class="arrow"></i>' +
                    '<a class="delect-btn">删除</a></div></a></div>';

            }
            $('.ui-content').html(str);
            $(".item").on('swipeleft', function(event) {
                event.preventDefault();
                $(this).addClass('selected').siblings('.item').removeClass('selected');
                $(this).find('.delect-btn').on('click', function(event) {
                    var _this=this;
                    event.preventDefault();
                    var delId=$(this).parent(".item").attr("id");
                    //将要删除的id传到后台
                    $.ajax({ type: "post",
                        url:'http://'+IP+'/data-center/CommonBoardDelete/getCommonBoardDeleteInfo?token='+userId,
                        dataType: "json",
                        headers:{"marker":userId},
                        data:{"paramData":'{reportId:'+delId+'}'},
                        success:function(result){
                            //console.log(result);
                            if(result.returnCode=='success') {
                                $(_this).parent(".item").animate({
                                        height: 0,
                                        width: 0
                                    },
                                    300,function () {
                                        $(_this).remove();
                                    });
                            }
                        },
                        error:function(err){
                            alert("删除失败");
                        }
                    });
                });
            });
            $(".item").on('swiperight', function(event) {
                event.preventDefault();
                $(this).removeClass('selected');
            });
        },
        error: function (err) {
            console.log("服务器链接失败");
        }});

});